/*
 * Created on 7/Abr/2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package org.cyborgas.xmltool.actions;

import java.io.File;

import org.cyborgas.xmltool.MainWindow;
import org.cyborgas.xmltool.Util;
import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;


/**
 * @author rino
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class FileOpenAction extends Action {
	
	private MainWindow window;

	public FileOpenAction(MainWindow window) {
		this.window = window;
		setText("&Open...");
		setAccelerator(SWT.MOD1 | 'O');
		setToolTipText("Open XML file");
		setImageDescriptor(Util.getImageDescriptor("fileopen"));
//			case XSL :
//				setText("&Open stylesheet...");
//				setToolTipText("Open XSL file");
//				break;
	}

	public void run() {
		FileDialog dialog =
			new FileDialog(window.getShell(), SWT.OPEN);
		dialog.setFilterExtensions(new String[] {"*.xml", "*.*"});
		dialog.open();
		
		String file = dialog.getFileName();
		if (file != null && !file.equals("")) {
			window.load(new File(dialog.getFilterPath(), file));
		}
	}
}
